package com.yuhf.utils;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.sql.Blob;
import java.sql.SQLException;

public class ConvertUtils {
	 public static byte[] toByte(Blob blob) throws SQLException, IOException{
		  byte[] im = new byte[(int) blob.length()];
		  BufferedInputStream is = new BufferedInputStream(blob.getBinaryStream());
		  int len = (int) blob.length();
		  int offset = 0;
		  int read = 0;
		  
		  try {
		   while (offset < len && (read = is.read(im, offset, len - offset)) >= 0) {
		     offset += read;
		    }
		  } catch (IOException e) {
		   e.printStackTrace();
		  }finally{
		   is.close();
		   is=null;
		  }
		  return im;
	 }
}
